package cn.teduymdj.jxc.controller;

import cn.teduymdj.jxc.myAnnotation.LogAnnotation;
import cn.teduymdj.jxc.pojo.dto.CustomerReturnListAddNewDTO02;
import cn.teduymdj.jxc.pojo.dto.SelectConditionDTO;
import cn.teduymdj.jxc.pojo.dto.SelectReturnCondition;
import cn.teduymdj.jxc.pojo.entity.Log;
import cn.teduymdj.jxc.pojo.vo.CustomerReturnListGoodsListItemVO;
import cn.teduymdj.jxc.pojo.vo.CustomerReturnListListItemVO;
import cn.teduymdj.jxc.service.CustomerReturnListGoodsService;
import cn.teduymdj.jxc.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户退货Controller层
 */
@Slf4j
@RestController
@RequestMapping("/customerReturnListGoods")
public class CustomerReturnListGoodsController {

    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;


    /**
     * 保存客户退货单信息
     *
     * @param customerReturnList         客户退货单信息实体
     * @param customerReturnListGoodsStr 客户退货信息JSON字符串
     * @return
     */
    //日志保存注解,不用管:李柯辰
    @LogAnnotation(content = "保存客户退货单信息", type = Log.INSERT_ACTION)
    @RequestMapping("/save")
    public JsonResult<Void> save(@RequestBody CustomerReturnListAddNewDTO02 customerReturnList) {
        customerReturnListGoodsService.save(customerReturnList);
        return JsonResult.ok();
    }

    /**
     * 查询客户退货单
     *
     * @param customerReturnNumber 单号
     * @param customerId           供应商ID
     * @param state                付款状态
     * @param sTime                开始时间
     * @param eTime                结束时间
     * @return
     */
    @LogAnnotation(content = "查询客户退货单", type = Log.SELECT_ACTION)
    @RequestMapping("/list")
    public JsonResult<List<CustomerReturnListListItemVO>> list(@RequestBody SelectConditionDTO selectConditionDTO) {


        List<CustomerReturnListListItemVO> customerReturnListList =
                customerReturnListGoodsService.getCustomerReturnlist(selectConditionDTO);

        return JsonResult.ok(customerReturnListList);
    }

    /**
     * 查询客户退货单商品信息
     *
     * @param customerReturnListId 客户退货单ID
     * @return
     */
    @LogAnnotation(content = "查询客户退货单商品信息", type = Log.SELECT_ACTION)
    @RequestMapping("/goodsList")
    public JsonResult<List<CustomerReturnListGoodsListItemVO>> goodsList(Long customerReturnListId) {

        List<CustomerReturnListGoodsListItemVO> customerReturnListGoodsList =
                customerReturnListGoodsService.getCustomerReturnListGoodsByCustomerReturnListId(customerReturnListId);

        return JsonResult.ok(customerReturnListGoodsList);
    }

    /**
     * 删除客户退货单及商品信息
     *
     * @param customerReturnListId 客户退货单ID
     * @return
     */
    @LogAnnotation(content = "删除客户退货单及商品信息", type = Log.DELETE_ACTION)
    @RequestMapping("/delete")
    public JsonResult<Void> delete(Long customerReturnListId) {

        customerReturnListGoodsService.delete(customerReturnListId);

        return JsonResult.ok();

    }





    /**
     * 修改进货单付款状态
     *
     * @param id 进货单ID
     * @return
     */
    @LogAnnotation(content = "修改进货单付款状态为付款", type = Log.UPDATE_ACTION)
    @PostMapping("/{id:[0-9]+}/Paid")
    public JsonResult<Void> setPaid(@PathVariable Long id) {
        log.debug("开始处理【启用管理员】的请求，参数：{}", id);
        customerReturnListGoodsService.setPaid(id);
        return JsonResult.ok();
    }

    /**
     * 修改进货单付款状态
     *
     * @param id 进货单ID
     * @return
     */
    @LogAnnotation(content = "修改进货单付款状态为未付款", type = Log.UPDATE_ACTION)
    @PostMapping("/{id:[0-9]+}/Unpaid")
    public JsonResult<Void> setUnpaid(@PathVariable Long id) {
        log.debug("开始处理【禁用管理员】的请求，参数：{}", id);
        customerReturnListGoodsService.setUnpaid(id);
        return JsonResult.ok();
    }

    /**
     * 客户退货商品统计
     *
     * @param sTime       开始时间
     * @param eTime       结束时间
     * @param goodsTypeId 商品类别ID
     * @param codeOrName  编号或商品名称
     * @return
     */
    @LogAnnotation(content = "客户退货商品统计", type = Log.SELECT_ACTION)
    @RequestMapping("/count")
    public JsonResult<List<CustomerReturnListGoodsListItemVO>> count
    (@RequestBody SelectReturnCondition selectReturnCondition) {
        List<CustomerReturnListGoodsListItemVO> customerReturnListGoodsList =
                customerReturnListGoodsService.getCustomerReturnListGoods(selectReturnCondition);
        return JsonResult.ok(customerReturnListGoodsList);
    }

}
